package com.struts.deal.admin.system;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.base.Constants;
import com.ibatis.po.system.TSysAdmin;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.lg.system.CSqlMap;
import com.lg.system.MessageBean;
import com.struts.web.user.manage.system.EditPassForm;

public class SysDeal {

	/**
	 * 用户修改密码
	 * @param request
	 * @param response
	 * @param aWebForm
	 * @return
	 * @throws SQLException
	 */
	public static MessageBean  modiPass(HttpServletRequest request,
            HttpServletResponse response,
            EditPassForm aWebForm) throws SQLException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TSysAdmin adminPo = (TSysAdmin)request.getSession().getAttribute("admin");
		MessageBean messageBean = new MessageBean();
		try{
			if(adminPo == null){ //判断用户是否超时或者非法登录
				messageBean.setMessage(Constants.USER_RE_LOGIN);
			}else{
				aWebForm.setId(adminPo.getId());
				if(aWebForm.getOldPass()!= null && aWebForm.getOldPass()!="" && aWebForm.getNewPass() != null && aWebForm.getNewPass()!=""){
				int temp = sqlmap.update("T_SYS_ADMIN.updatePass",aWebForm);
				    if(temp>0){
				    	messageBean.setResult(true);
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return messageBean;
	}
}
